import 'package:demo/ui/display/display_router.dart';
import 'package:demo/ui/home/home_router.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart';

import '../ui/home/404.dart';
import '../ui/home/home_page.dart';
import '../ui/home/webview_page.dart';
import '../ui/login/login_router.dart';
import 'router_init.dart';

class Routes {
  static String home = "/home";
  static String webViewPage = "/webview";

  static List<IRouterProvider> _listRouter = [];

  static void configureRoutes(Router router) {
    router.notFoundHandler = Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      debugPrint("未找到目标页面");
      return NotFoundWidget();
    });

    router.define(home, handler: new Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> map) {
      return HomePage();
    }));

    router.define(webViewPage, handler: new Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> map) {
      String title = map['title']?.first;
      String url = map['url']?.first;
      return WebViewPage(title: title, url: url);
    }));

    _listRouter.clear();

    /// 各自路由由各自模块管理，统一在此添加初始化
    _listRouter.add(LoginRouter());
    _listRouter.add(HomeRouter());
    _listRouter.add(DisplayRouter());

    ///注册
    _listRouter.forEach((routerProvider) {
      routerProvider.initRouter(router);
    });
  }
}
